package com.zs.pig.api.controller;

import com.zs.pig.api.formbean.BaseResultVo;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

/**
 * Created by zsCat on 16-1-4.
 **/
public class BaseApiController {
    private static final Log LOGGER = LogFactory.getLog(BaseApiController.class);

    SerializerFeature[] feature = { SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteNullListAsEmpty,
            SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullBooleanAsFalse, SerializerFeature.WriteMapNullValue };

    /**
     *
     * @param resultData
     * @return
     */
    protected String buildSuccessResultInfo(Object resultData) {
        LOGGER.debug(String.format("enter function, %s", resultData));
        BaseResultVo resultVo = new BaseResultVo();
        resultVo.setResultData(resultData);
        resultVo.setResultMessage("success");
        return JSON.toJSONString(resultVo, feature);
    }


    protected String buildFailedResultInfo(int resultCode, String failedMsg) {
        BaseResultVo resultVo = new BaseResultVo(resultCode, failedMsg);
        return JSON.toJSONString(resultVo, feature);
    }



}
